package com.social.controller;

import com.social.dao.ActivityDao;
import com.social.pojo.Activity;
import com.social.pojo.Result;
import com.social.pojo.vto.ActivityVTO;
import com.social.service.ActivityService;
import com.social.service.impl.ActivityServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.websocket.server.PathParam;

/**
 * @className: ActivityController
 * @description: TODO 类描述
 * @author: XiaoXu
 * @date: 2022/10/09 19:13
 **/
@Api(tags = "ActivityController")
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Resource
    private ActivityService activityService;

    @PostMapping
    public Result insert(@Validated(Activity.add.class) @RequestBody  Activity activity){
        /**
            * @Author XiaoXu
            * @Date 2022/10/9
            * @Param [activity]
            * @Return Result
            * @Description 保存活动信息
         */

        return activityService.insert(activity);
    }

    @GetMapping("/details")
    public Result getActivityById(@RequestParam Long id){
        /**
            * @Author XiaoXu
            * @Date 2022/10/24
            * @Param [id]
            * @Return Result
            * @Description 根据id查活动
         */
        System.out.println("id:"+id);
        return activityService.getActivityById(id);
    }

    @GetMapping("/detail")
    public Result getDetail(@RequestParam Long id){
        return activityService.getDetail(id);
    }

    @PostMapping ("/list")
    public Result getActivityByCondition(@RequestBody ActivityVTO activityVTO){
        return activityService.getActivityByCondition(activityVTO);
    }

    @PostMapping("/allList")
    public Result getAllList(@RequestBody ActivityVTO activityVTO){
        return activityService.getAllList(activityVTO);
    }
    @PostMapping("/update")
    public Result updateActivity(@Validated(Activity.update.class) @RequestBody Activity activity){
        /**
            * @Author XiaoXu
            * @Date 2022/10/24
            * @Param [id]
            * @Return Result
            * @Description 根据id修改活动信息
         */
        return activityService.updateActivity(activity);
    }

    @GetMapping("/ranking")
    public Result getRanking(@RequestParam Integer size, @RequestParam Integer index){
        return activityService.getRanking(size,index);
    }

    @GetMapping("/photos")
    public Result getPhotos(@RequestParam Integer size, @RequestParam Integer index){
        return activityService.getPhotos(size,index);
    }
}
